<?php
class ObjectModel extends Model{
	public $validate=array(
		array('name','nonull','栏目名不能为空',2,3)
	);
	public $table ='object';
	public function add_vote(){
		if($this->create()){
			if(!empty($_FILES['pic']['name'])){
				$upload = new Upload('upload/article/'.date("Y/m/d"));
				$file = $upload->upload();
				$this->data['pic']=$file[0]['path'];
			}
			return $this->add();
		}
	}
	public function edit_vote(){
		if($this->create()){
			if(!empty($_FILES['pic']['name'])){
				$upload = new Upload('upload/article/'.date("Y/m/d"));
				$file = $upload->upload();
				$this->data['pic']=$file[0]['path'];
				//删除旧的缩略图
				$pic= $this->where("oid=".Q("oid"))->getField('pic');
				is_file($pic)and unlink($pic);
			}
			return $this->save();
		}
	}
	public function del_vote(){
		$oid=Q("oid");
		if( is_array($oid)){
			foreach($oid as $id){
				$pic= $this->where("oid=".$id)->getField('pic');
				is_file($pic)and unlink($pic);
			}
		}else{
			$pic= $this->where("oid=".$oid)->getField('pic');
			is_file($pic)and unlink($pic);
		}
		return $this->del($oid);
		
	}
	
}